package com.jiyun.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.mapper.ThRewardMapper;
import com.jiyun.pojo.ThOrder;
import com.jiyun.pojo.ThReward;
import com.jiyun.service.IThOrderService;
import com.jiyun.service.IThRewardService;
import common.models.dtos.RewardDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author usian
 * @since 2022-10-25
 */
@Service
public class ThRewardServiceImpl extends ServiceImpl<ThRewardMapper, ThReward> implements IThRewardService {

    @Autowired
    private IThOrderService thOrderService;


    @Override
    public String findorderId(RewardDto dto) {
        List<ThOrder> thOrders = thOrderService.orderByDESC();
        ThOrder thOrder = thOrders.get(0);
        ThReward thReward=new ThReward();
        thReward.setRewartType(dto.getRewart_type());    //奖励类型  1-金钱  2-旅游 3-梦想
        thReward.setRewardContent(dto.getReward_content()); //奖励内容
        thReward.setSotreName(thOrder.getStoreName());   //门店名称
        thReward.setCreateTime(new Date());   //录入时间
        thReward.setImplementTime(dto.getImplement_time());  //执行时间

        boolean save = this.save(thReward);
        if (!save){
            throw new RuntimeException("添加奖励有误");
        }
        return "奖励成功";
    }
}
